package org.csu.tank.ui;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.components.HealthIntComponent;
import com.almasb.fxgl.texture.Texture;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.csu.tank.GameConfig;
import org.csu.tank.GameType;
import org.csu.tank.client.TankClient;
import org.csu.tank.components.PlayerComponent;

import java.util.List;

import static com.almasb.fxgl.dsl.FXGL.*;
import static com.almasb.fxgl.dsl.FXGL.getip;

/**
 * PVP模式下的右侧信息栏
 */
public class PVPInfoPane extends Pane {
    public PVPInfoPane() {

        TilePane tilePane = new TilePane(10, 10);
        tilePane.setAlignment(Pos.TOP_LEFT);
        tilePane.setPrefSize(65, 390);
        getip("nowEnemyNum").addListener((ob, ov, nv) -> {
            tilePane.getChildren().clear();
            for (int i = 0; i < nv.intValue(); i++) {
                tilePane.getChildren().add(texture("ui/enemy_pre.png"));
            }
        });
        tilePane.setLayoutX(25);
        tilePane.setLayoutY(50);


        Label hp = new Label("HP");
        hp.setFont(new Font("HP",43));
        hp.setLayoutX(35);
        hp.setLayoutY(400);

        HBox hBox = new HBox();
        Texture hpTexture = texture("ui/hp.png");
        hpTexture.setFitHeight(35);
        hpTexture.setFitWidth(35);
        Text hpText = getUIFactoryService().newText("", Color.BLACK, 35);
        hpText.textProperty().bind(getGameWorld().getEntitiesByType(GameType.PLAYER).get(0).getComponent(HealthIntComponent.class).valueProperty().asString());
        hBox.getChildren().addAll(hpTexture,hpText);
        hBox.setLayoutX(35);
        hBox.setLayoutY(450);

        Texture levelFlag = texture("ui/levelFlag.png");
        levelFlag.setLayoutX(25);
        levelFlag.setLayoutY(520);

        Text levelText = getUIFactoryService().newText("", Color.BLACK, 43);
        levelText.setLayoutX(30);
        levelText.setLayoutY(600);
        levelText.setText("PVP");


        getChildren().addAll(tilePane,hp,hBox,levelFlag, levelText);
        setPrefSize(24 * 6, 24 * 28);
        setLayoutX(24 * 28);
        setLayoutY(0);

        setStyle("-fx-background-color: #666666");
    }
}
